package com.learn.tools.system;

import java.util.ResourceBundle;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 项目启动加载项
 * 
 * @author: liangan
 * @version  1.0.0
 */
public class AppLoaderListener implements ServletContextListener {
	private static final Logger log = LoggerFactory.getLogger(AppLoaderListener.class);

	private static ResourceBundle link = ResourceBundle.getBundle("link");

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext sc = sce.getServletContext();
		// ABSOLUTE_PATH
		AppSystemConstants.ABSOLUTE_PATH = sc.getRealPath("/").replace("\\",
				"/");
		log.info("AppSystemConstants.ABSOLUTE_PATH:[{}]", AppSystemConstants.ABSOLUTE_PATH);
		// CTX
		AppSystemConstants.CTX = sc.getContextPath();
		sc.setAttribute("ctx", AppSystemConstants.CTX);
		log.info("AppSystemConstants.CTX:[{}]",  AppSystemConstants.CTX);
		// STC
		try {
			AppSystemConstants.STC = link.getString("stc");
		} catch (Exception e) {
			AppSystemConstants.STC = AppSystemConstants.CTX;
		}
		sc.setAttribute("stc", AppSystemConstants.STC);
		log.info("AppSystemConstants.STC:[{}]",  AppSystemConstants.STC);
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

	}
}
